﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using S4Store.Domain.Report;
using S4Store.Domain;

namespace S4Store.Models.TelSellerKpi
{
    public class SellerKpiPersonBodyModel
    {
        public SellerKpiPersonBodyModel()
        {
            Reports = new List<SellerPersonBrandReport>();
        }

        public List<SellerPersonBrandReport> Reports { get; set; }

        public List<Employee> Sellers
        {
            get
            {
                return Reports.GroupBy(t => t.Seller).Select(t => t.Key).ToList(); 
            }
        }

        public List<CarBrand> GetCarBrands(Employee seller)
        {           
            return Reports.Where(t=>t.Seller.Id==seller.Id).GroupBy(t => t.CarBrand).Select(t => t.Key).ToList();            
        }

        public SellerPersonBrandReport GetReportByBrandAndSeller(Employee seller,CarBrand brand)
        {
            var model= Reports.FirstOrDefault(t => t.CarBrand.Id == brand.Id&&t.Seller.Id==seller.Id);
            if (model == null)
            {
                model = new SellerPersonBrandReport();
            }
            return model;
        }

    }
}